Services Layer
The services layer contains API and business logic services for the application
Details
- 📁 Absolute Path:
@s - 📁 Folder Location:
src/services
Layer Import and Usage Rules
| Action | base | components | libs | modules | views | app | services |
|---|---|---|---|---|---|---|---|
| 📥 Can Import From | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ |
| 📤 Can Export To | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ |
Key:
- ✅ Allowed: The layer can import from or export to the specified layer.
- ❌ Not Allowed: The layer cannot import from or export to the specified layer.
The services layer contains API and business logic services for the application. It is responsible for handling data fetching, manipulation, and business logic operations. The services layer is used by the modules, views, and app layers to fetch data from APIs, perform business logic operations, and manage the state of the application.
1. Purpose of the services Layer
The services layer is responsible for:
- Handling data fetching and manipulation
- Performing business logic operations
- Managing the state of the application
- Providing data to the
modules,views, andapplayers - Abstracting the data fetching and business logic operations from the
modules,views, andapplayers
2. Structure of the services Layer
- Small Project
- Large Project
src/
└── services/
├── api/ # API services
| ├── user.ts # User API service
| ├── product.ts # Product API service
| └── ... # Other API services
├── business/ # Business logic services
| ├── user.ts # User business logic service
| ├── product.ts # Product business logic service
| └── ... # Other business logic services
src/
└── services/
├── api/ # API services
| ├── user.ts # User API service
| ├── product.ts # Product API service
| └── ... # Other API services
├── business/ # Business logic services
| ├── user.ts # User business logic service
| ├── product.ts # Product business logic service
| └── ... # Other business logic services
├── libs/ # Utility functions and helpers
| ├── request.ts # Request utility function
| ├── response.ts # Response utility function
| └── ... # Other utility functions
3. Usage of the services Layer
src/services/api/user.ts
import {axios} from "@s/api/request";
export async function getUser() {
const response = await axios.get('/user');
return response.data;
}
4. Files in the services Layer
The services layer contains the following files:
api/- Contains API servicesbusiness/- Contains business logic services